package com.zyy.game.tianlong.callback;

import com.alibaba.fastjson.JSONException;
import com.zyy.game.tianlong.network.GameContext;
import com.zyy.game.tianlong.network.callback.EventExceptionCallBack;
import com.zyy.game.tianlong.network.exception.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author relufi
 * @date 2019/7/24 0024
 */
@Component
@Slf4j
public class EventExceptionCallBackImpl implements EventExceptionCallBack {

    /**
     * 异常回调 此回调由业务线程执行
     *
     * @param ctx   连接处理器上下文
     * @param cause 异常
     */
    @Override
    public void exceptionCaught(GameContext ctx, Throwable cause) {
        if(cause instanceof ApiException) {
            log.debug("根据code未找到事件",cause);
        }else if(cause instanceof JSONException) {
            log.debug("JSON格式化错误",cause);
        }else {
            log.error("异常", cause);
        }
    }
}
